﻿/*********************************************************************
 *
 *                             NOTICE
 *               COPYRIGHT (c) 2012 Panoscopix Software, Inc.
 *                UNPUBLISHED - ALL RIGHTS RESERVED
 * 
 *      This program is confidential, proprietary, and a trade
 *   secret of Panoscopix Software, Inc. The receipt or possession of
 *     this program does not convey any rights to reproduce or
 *      disclose its contents, or to manufacture, use, or sell
 *       anything that it may describe, in whole or in part, 
 *   without the specific written consent of Panoscopix Software, Inc.
 *
 * Implementation of Input Generator interface using test data.
 * 
 *******************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FileSystem.Utility;

namespace FileSystem.Test
{
    class TestCoordinator : IInputGenerator, IOutputSink
    {
        private TestCase test;
	    private StringBuilder response;
	
	    public TestCoordinator(TestCase test) {
		    this.test = test;
		    response = new StringBuilder();
	    }
	
	    public String readInputLine() //throws IOException
        {
		    return readInputLineSafe();
	    }
	
	    public String readInputLineSafe() {
		    if (response.Length != 0) {
			    if (!test.evalResponseToPreviousLine(response.ToString())) {
				    return "END";
			    }
		    }
		    response = new StringBuilder();
		    String input = test.getLine();
		    if (null == input) return "END";
		    return input;
	    }
	
	    public void print(String output) {
		    response.Append(output);
		    ConsoleOutUtil.print(output);
	    }

	    public void println(String output) {
		    response.Append(output).Append("\n");
		    ConsoleOutUtil.println(output);
	    }
    }
}
